home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-28 | 708 b | 25 lines | [TEXT/KEEN] |
- #$AddLineNumbers
- #Intended for use on one specific file at a time -
- #use the "Select input file..." option under the "Take input from:" popup
- #to select the file to be numbered.
-
- BEGIN { outfile = ARGV[1]; }#remember the input file name
-
- #collect numbered lines in an array, justifying line numbers
- { if (NF == 0 || (NF == 1 && $1 == " "))#that's an option-space there
- out[NR] = $0;
- else if (NR >= 1000)
- out[NR] = NR "\t" $0;
- else if (NR >= 100)
- out[NR] = " " NR "\t" $0;
- else if (NR >= 10)
- out[NR] = " " NR "\t" $0;
- else
- out[NR] = " " NR "\t" $0;
- }
-
- END { close(outfile);#a nice touch when switching from read to write
- for (i = 1; i <= NR; ++i)
- print out[i] > outfile
- }
-